package com.andaily.web.controller.mobile.account;

import com.andaily.domain.dto.account.AccountTypeOverviewDTO;
import com.andaily.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/account_type")
public class AccountTypeController {

    private AccountService accountService;

    @RequestMapping("overview")
    public String overview(AccountTypeOverviewDTO overviewDTO, ModelMap model) throws Exception {
        overviewDTO = accountService.loadAccountTypeOverview(overviewDTO);
        model.put("accountTypeOverview", overviewDTO);
        return "account/type/account_type_overview";
    }

    @RequestMapping("confirm_delete/{guid}")
    public String confirmDelete(@PathVariable() String guid, ModelMap model) throws Exception {
        model.addAttribute("accountTypeGuid", guid);
        return "account/type/account_type_delete_confirm";
    }

    @RequestMapping("delete/{guid}")
    public String delete(@PathVariable() String guid) throws Exception {
        accountService.archivedAccountType(guid);
        return "redirect:/m/account_type/overview";
    }


    @Autowired
    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
}
